
<!DOCTYPE HTML>
<html lang="zh-hans" >
<head>
    <meta charset="UTF-8">
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
    <title>15.6：App入口及首页 · 《Flutter实战》</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge"/>
    <meta name="baidu-site-verification" content="Y34sAqDKUH"/>
    <meta name="theme-color" content="#ffffff">
    <!--<meta name="description" content="">-->
    <meta name="description" content="《Flutter实战》是Flutter中文网（https://flutterchina.club）开源的电子书，旨在帮助开发者系统化的了解并学习Flutter。">
    <meta name="keywords" content="flutter实战,flutter书籍,flutter电子书,flutter中文网 ">
    <meta name="generator" content="GitBook 3.2.3">
    
    <meta name="author" content="wendux 824783146@qq.com">
    
    
    
    
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/flutterchina/flutter-in-action/_book/gitbook/style.css">

    
    
    
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/flutterchina/flutter-in-action/_book/gitbook/gitbook-plugin-search-pro/search.css">
    
    
    
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/flutterchina/flutter-in-action/_book/gitbook/gitbook-plugin-ace/ace.css">
    
    
    
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/flutterchina/flutter-in-action/_book/gitbook/gitbook-plugin-splitter/splitter.css">
    
    
    
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/flutterchina/flutter-in-action/_book/gitbook/gitbook-plugin-prism/prism.css">
    
    
    
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/flutterchina/flutter-in-action/_book/gitbook/gitbook-plugin-donate/plugin.css">
    
    
    
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/flutterchina/flutter-in-action/_book/gitbook/gitbook-plugin-fontsettings/website.css">
    
    
    

    

    
        
    
        
    
        
    
        
    
        
    

    
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="https://cdn.jsdelivr.net/gh/flutterchina/flutter-in-action/_book/gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="https://cdn.jsdelivr.net/gh/flutterchina/flutter-in-action/_book/gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="login_page.html" />
    
    
    <link rel="prev" href="network.html" />
    

    <style>
        .pull-right > i {
            font-size: 25px;
            color: #777 !important;
            cursor: pointer;

        }

        .pull-right > i:hover {
            color: #777 !important;
        }

        body {
            font-size: 15px !important;
        }

        a[href='../todo.html'], a[href='todo.html'] {
            color: #888 !important;
        }

        .copyright {
            text-align: center;
            margin: 80px 16px 30px 16px;
            padding-top: 16px;
            border-top: #eee 1px solid;
            color: grey;
            font-size: .9em;
        }

        .ad {
            color: white;
            text-align: center;
            background: url(https://img.alicdn.com/tfs/TB1Huu7vMmTBuNjy1XbXXaMrVXa-2880-400.png);
            background-size: cover;
            cursor: pointer;
            margin-bottom: 30px;
            padding: 18px
        }

        .ad:hover {
            opacity: .8;
        }
    </style>
</head>
<body>
<!--<div id="ad" style="display: none">-->
    <!--<div class="ad ad0"-->
         <!--onclick="_track('aliyun','https://promotion.aliyun.com/ntms/yunparter/invite.html?userCode=8hhi4dts')">-->
        <!--<div style="font-size: 1.3em; padding-right: 120px; position: relative; top: 12px">阿里云新春特惠</div>-->
        <!--<div style="color:orange; font-size: 13px">限时红包 最高￥<span style="font-size: 40px">1888</span></div>-->
    <!--</div>-->
    <!--<div class="ad ad1"-->
         <!--onclick="_track('aliyun-puhui','https://promotion.aliyun.com/ntms/act/qwbk.html?spm=5176.11533457.1089570.10.74e877e33jtaGy&userCode=8hhi4dts')">-->
        <!--<div style="font-size: 1.5em;">阿里云全民云计算-新春特惠</div>-->
        <!--<div style="color:orange; font-size: 18px;padding-top: 4px;">普惠上云，云服务器1核1G仅需293元/年</div>-->
    <!--</div>-->
<!--</div>-->

<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="输入并搜索" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    
    
        
        <li>
            <a href="https://flutterchina.club" target="_blank" class="custom-link"><div><img height=20 style='position:relative; top:5px; padding-right:5px ' src='https://cdn.jsdelivr.net/gh/flutterchina/website@1.0/images/favicon.png'/> Flutter中文网</div></a>
        </li>
    
    

    
    <li class="divider"></li>
    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../intro.html">
            
                <a href="../intro.html">
            
                    
                    前言
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">入门篇</li>
        
        
    
        <li class="chapter " data-level="2.1" data-path="../chapter1/">
            
                <a href="../chapter1/">
            
                    
                    第一章：起步
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.1.1" data-path="../chapter1/mobile_development_intro.html">
            
                <a href="../chapter1/mobile_development_intro.html">
            
                    
                    1.1：移动开发技术简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.2" data-path="../chapter1/flutter_intro.html">
            
                <a href="../chapter1/flutter_intro.html">
            
                    
                    1.2：初识Flutter
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.3" data-path="../chapter1/install_flutter.html">
            
                <a href="../chapter1/install_flutter.html">
            
                    
                    1.3：搭建Flutter开发环境
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.1.4" data-path="../chapter1/dart.html">
            
                <a href="../chapter1/dart.html">
            
                    
                    1.4：Dart语言简介
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="../chapter2/">
            
                <a href="../chapter2/">
            
                    
                    第二章：第一个Flutter应用
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.2.1" data-path="../chapter2/first_flutter_app.html">
            
                <a href="../chapter2/first_flutter_app.html">
            
                    
                    2.1：计数器示例
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.2.2" data-path="../chapter2/flutter_router.html">
            
                <a href="../chapter2/flutter_router.html">
            
                    
                    2.2：路由管理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.2.3" data-path="../chapter2/flutter_package_mgr.html">
            
                <a href="../chapter2/flutter_package_mgr.html">
            
                    
                    2.3：包管理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.2.4" data-path="../chapter2/flutter_assets_mgr.html">
            
                <a href="../chapter2/flutter_assets_mgr.html">
            
                    
                    2.4：资源管理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.2.5" data-path="../chapter2/flutter_app_debug.html">
            
                <a href="../chapter2/flutter_app_debug.html">
            
                    
                    2.5：调试Flutter APP
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.2.6" data-path="../chapter2/thread_model_and_error_report.html">
            
                <a href="../chapter2/thread_model_and_error_report.html">
            
                    
                    2.6：Dart线程模型及异常捕获
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.3" data-path="../chapter3/">
            
                <a href="../chapter3/">
            
                    
                    第三章：基础组件
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.3.1" data-path="../chapter3/flutter_widget_intro.html">
            
                <a href="../chapter3/flutter_widget_intro.html">
            
                    
                    3.1：Widget简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.2" data-path="../chapter3/state_manage.html">
            
                <a href="../chapter3/state_manage.html">
            
                    
                    3.2：状态管理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.3" data-path="../chapter3/text.html">
            
                <a href="../chapter3/text.html">
            
                    
                    3.3：文本、字体样式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.4" data-path="../chapter3/buttons.html">
            
                <a href="../chapter3/buttons.html">
            
                    
                    3.4：按钮
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.5" data-path="../chapter3/img_and_icon.html">
            
                <a href="../chapter3/img_and_icon.html">
            
                    
                    3.5：图片和Icon
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.6" data-path="../chapter3/radio_and_checkbox.html">
            
                <a href="../chapter3/radio_and_checkbox.html">
            
                    
                    3.6：单选框和复选框
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.7" data-path="../chapter3/input_and_form.html">
            
                <a href="../chapter3/input_and_form.html">
            
                    
                    3.7：输入框和表单
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.3.8" data-path="../chapter3/progress.html">
            
                <a href="../chapter3/progress.html">
            
                    
                    3.8：进度指示器
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.4" data-path="../chapter4/">
            
                <a href="../chapter4/">
            
                    
                    第四章：布局类组件
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.4.1" data-path="../chapter4/intro.html">
            
                <a href="../chapter4/intro.html">
            
                    
                    4.1：布局类组件简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.4.2" data-path="../chapter4/row_and_column.html">
            
                <a href="../chapter4/row_and_column.html">
            
                    
                    4.2：线性布局（Row、Column）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.4.3" data-path="../chapter4/flex.html">
            
                <a href="../chapter4/flex.html">
            
                    
                    4.3：弹性布局（Flex）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.4.4" data-path="../chapter4/wrap_and_flow.html">
            
                <a href="../chapter4/wrap_and_flow.html">
            
                    
                    4.4：流式布局（Wrap、Flow）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.4.5" data-path="../chapter4/stack.html">
            
                <a href="../chapter4/stack.html">
            
                    
                    4.5：层叠布局（Stack、Positioned）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.4.6" data-path="../chapter4/alignment.html">
            
                <a href="../chapter4/alignment.html">
            
                    
                    4.6：对齐与相对定位（Align）
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.5" data-path="../chapter5/">
            
                <a href="../chapter5/">
            
                    
                    第五章：容器类组件
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.5.1" data-path="../chapter5/padding.html">
            
                <a href="../chapter5/padding.html">
            
                    
                    5.1：填充（Padding）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.5.2" data-path="../chapter5/constrainedbox_and_sizebox.html">
            
                <a href="../chapter5/constrainedbox_and_sizebox.html">
            
                    
                    5.2：尺寸限制类容器（ConstrainedBox等）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.5.3" data-path="../chapter5/decoratedbox.html">
            
                <a href="../chapter5/decoratedbox.html">
            
                    
                    5.3：装饰容器（DecoratedBox）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.5.4" data-path="../chapter5/transform.html">
            
                <a href="../chapter5/transform.html">
            
                    
                    5.4：变换（Transform）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.5.5" data-path="../chapter5/container.html">
            
                <a href="../chapter5/container.html">
            
                    
                    5.5：Container容器
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.5.6" data-path="../chapter5/material_scaffold.html">
            
                <a href="../chapter5/material_scaffold.html">
            
                    
                    5.6：Scaffold、TabBar、底部导航
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.5.7" data-path="../chapter5/clip.html">
            
                <a href="../chapter5/clip.html">
            
                    
                    5.7：剪裁（Clip）
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.6" data-path="../chapter6/">
            
                <a href="../chapter6/">
            
                    
                    第六章：可滚动组件
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.6.1" data-path="../chapter6/intro.html">
            
                <a href="../chapter6/intro.html">
            
                    
                    6.1：可滚动组件简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.6.2" data-path="../chapter6/single_child_scrollview.html">
            
                <a href="../chapter6/single_child_scrollview.html">
            
                    
                    6.2：SingleChildScrollView
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.6.3" data-path="../chapter6/listview.html">
            
                <a href="../chapter6/listview.html">
            
                    
                    6.3：ListView
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.6.4" data-path="../chapter6/gridview.html">
            
                <a href="../chapter6/gridview.html">
            
                    
                    6.4：GridView
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.6.5" data-path="../chapter6/custom_scrollview.html">
            
                <a href="../chapter6/custom_scrollview.html">
            
                    
                    6.5：CustomScrollView
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.6.6" data-path="../chapter6/scroll_controller.html">
            
                <a href="../chapter6/scroll_controller.html">
            
                    
                    6.6：滚动监听及控制（ScrollController）
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="2.7" data-path="../chapter7/">
            
                <a href="../chapter7/">
            
                    
                    第七章：功能型组件
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="2.7.1" data-path="../chapter7/willpopscope.html">
            
                <a href="../chapter7/willpopscope.html">
            
                    
                    7.1：导航返回拦截（WillPopScope）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.7.2" data-path="../chapter7/inherited_widget.html">
            
                <a href="../chapter7/inherited_widget.html">
            
                    
                    7.2：数据共享（InheritedWidget）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.7.3" data-path="../chapter7/provider.html">
            
                <a href="../chapter7/provider.html">
            
                    
                    7.3： 跨组件状态共享（Provider）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.7.4" data-path="../chapter7/theme.html">
            
                <a href="../chapter7/theme.html">
            
                    
                    7.4：颜色和主题（Theme）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.7.5" data-path="../chapter7/futurebuilder_and_streambuilder.html">
            
                <a href="../chapter7/futurebuilder_and_streambuilder.html">
            
                    
                    7.5：异步UI更新（FutureBuilder、StreamBuilder）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.7.6" data-path="../chapter7/dailog.html">
            
                <a href="../chapter7/dailog.html">
            
                    
                    7.6：对话框详解
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    
        
        <li class="header">进阶篇</li>
        
        
    
        <li class="chapter " data-level="3.1" data-path="../chapter8/">
            
                <a href="../chapter8/">
            
                    
                    第八章：事件处理与通知
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.1.1" data-path="../chapter8/listener.html">
            
                <a href="../chapter8/listener.html">
            
                    
                    8.1：原始指针事件处理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.2" data-path="../chapter8/gesture.html">
            
                <a href="../chapter8/gesture.html">
            
                    
                    8.2：手势识别
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.3" data-path="../chapter8/eventbus.html">
            
                <a href="../chapter8/eventbus.html">
            
                    
                    8.3：全局事件总线
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.1.4" data-path="../chapter8/notification.html">
            
                <a href="../chapter8/notification.html">
            
                    
                    8.4：通知(Notification)
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3.2" data-path="../chapter9/">
            
                <a href="../chapter9/">
            
                    
                    第九章：动画
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.2.1" data-path="../chapter9/intro.html">
            
                <a href="../chapter9/intro.html">
            
                    
                    9.1：Flutter动画简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2.2" data-path="../chapter9/animation_structure.html">
            
                <a href="../chapter9/animation_structure.html">
            
                    
                    9.2：动画结构
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2.3" data-path="../chapter9/route_transition.html">
            
                <a href="../chapter9/route_transition.html">
            
                    
                    9.3：自定义路由过渡动画
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2.4" data-path="../chapter9/hero.html">
            
                <a href="../chapter9/hero.html">
            
                    
                    9.4：Hero动画
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2.5" data-path="../chapter9/stagger_animation.html">
            
                <a href="../chapter9/stagger_animation.html">
            
                    
                    9.5：交织动画
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2.6" data-path="../chapter9/animated_switcher.html">
            
                <a href="../chapter9/animated_switcher.html">
            
                    
                    9.6：通用"切换动画"组件（AnimatedSwitcher）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.2.7" data-path="../chapter9/animated_widgets.html">
            
                <a href="../chapter9/animated_widgets.html">
            
                    
                    9.7：动画过渡组件
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3.3" data-path="../chapter10/">
            
                <a href="../chapter10/">
            
                    
                    第十章：自定义组件
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.3.1" data-path="../chapter10/intro.html">
            
                <a href="../chapter10/intro.html">
            
                    
                    10.1：自定义组件方法简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.3.2" data-path="../chapter10/combine.html">
            
                <a href="../chapter10/combine.html">
            
                    
                    10.2：组合现有组件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.3.3" data-path="../chapter10/turn_box.html">
            
                <a href="../chapter10/turn_box.html">
            
                    
                    10.3：组合实例：TurnBox
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.3.4" data-path="../chapter10/custom_paint.html">
            
                <a href="../chapter10/custom_paint.html">
            
                    
                    10.4：自绘组件（CustomPaint与Canvas）
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.3.5" data-path="../chapter10/gradient_circular_progress_demo.html">
            
                <a href="../chapter10/gradient_circular_progress_demo.html">
            
                    
                    10.5：自绘实例：圆形渐变进度条(自绘)
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3.4" data-path="../chapter11/">
            
                <a href="../chapter11/">
            
                    
                    第十一章：文件操作与网络请求
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.4.1" data-path="../chapter11/file_operation.html">
            
                <a href="../chapter11/file_operation.html">
            
                    
                    11.1：文件操作
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.4.2" data-path="../chapter11/http.html">
            
                <a href="../chapter11/http.html">
            
                    
                    11.2：Http请求-HttpClient
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.4.3" data-path="../chapter11/dio.html">
            
                <a href="../chapter11/dio.html">
            
                    
                    11.3：Http请求-Dio package
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.4.4" data-path="../chapter11/download_with_chunks.html">
            
                <a href="../chapter11/download_with_chunks.html">
            
                    
                    11.4：实例：Http分块下载
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.4.5" data-path="../chapter11/websocket.html">
            
                <a href="../chapter11/websocket.html">
            
                    
                    11.5：WebSocket
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.4.6" data-path="../chapter11/socket.html">
            
                <a href="../chapter11/socket.html">
            
                    
                    11.6：使用Socket API
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.4.7" data-path="../chapter11/json_model.html">
            
                <a href="../chapter11/json_model.html">
            
                    
                    11.7：Json转Dart Model类
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3.5" data-path="../chapter12/">
            
                <a href="../chapter12/">
            
                    
                    第十二章：包与插件
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.5.1" data-path="../chapter12/develop_package.html">
            
                <a href="../chapter12/develop_package.html">
            
                    
                    12.1：开发package
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.5.2" data-path="../chapter12/platform-channel.html">
            
                <a href="../chapter12/platform-channel.html">
            
                    
                    12.2：平台通道简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.5.3" data-path="../chapter12/develop_plugin.html">
            
                <a href="../chapter12/develop_plugin.html">
            
                    
                    12.3：开发Flutter插件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.5.4" data-path="../chapter12/android_implement.html">
            
                <a href="../chapter12/android_implement.html">
            
                    
                    12.4：插件开发：实现Android端API
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.5.5" data-path="../chapter12/ios_implement.html">
            
                <a href="../chapter12/ios_implement.html">
            
                    
                    12.5：插件开发：实现IOS端API
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.5.6" data-path="../chapter12/texture_platformview.html">
            
                <a href="../chapter12/texture_platformview.html">
            
                    
                    12.6：Texture和PlatformView
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3.6" data-path="../chapter13/">
            
                <a href="../chapter13/">
            
                    
                    第十三章：国际化
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.6.1" data-path="../chapter13/multi_languages_support.html">
            
                <a href="../chapter13/multi_languages_support.html">
            
                    
                    13.1：让App支持多语言
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.6.2" data-path="../chapter13/locallization_implement.html">
            
                <a href="../chapter13/locallization_implement.html">
            
                    
                    13.2：实现Localizations
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.6.3" data-path="../chapter13/intl.html">
            
                <a href="../chapter13/intl.html">
            
                    
                    13.3：使用Intl包
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.6.4" data-path="../chapter13/faq.html">
            
                <a href="../chapter13/faq.html">
            
                    
                    13.4：国际化常见问题
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="3.7" data-path="../chapter14/">
            
                <a href="../chapter14/">
            
                    
                    第十四章：Flutter核心原理
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="3.7.1" data-path="../chapter14/flutter_ui_system.html">
            
                <a href="../chapter14/flutter_ui_system.html">
            
                    
                    14.1：Flutter UI系统
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.7.2" data-path="../chapter14/element_buildcontext.html">
            
                <a href="../chapter14/element_buildcontext.html">
            
                    
                    14.2：Element和BuildContext
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.7.3" data-path="../chapter14/render_object.html">
            
                <a href="../chapter14/render_object.html">
            
                    
                    14.3：RenderObject与RenderBox
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.7.4" data-path="../chapter14/flutter_app_startup.html">
            
                <a href="../chapter14/flutter_app_startup.html">
            
                    
                    14.4：Flutter从启动到显示
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="3.7.5" data-path="../chapter14/image_and_cache.html">
            
                <a href="../chapter14/image_and_cache.html">
            
                    
                    14.5：Flutter图片加载与缓存
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    
        
        <li class="header">实例篇</li>
        
        
    
        <li class="chapter " data-level="4.1" data-path="intro.html">
            
                <a href="intro.html">
            
                    
                    第十五章：一个完整的Flutter应用
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="4.1.1" data-path="intro.html">
            
                <a href="intro.html">
            
                    
                    15.1：应用简介
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.2" data-path="code_structure.html">
            
                <a href="code_structure.html">
            
                    
                    15.2：APP代码结构
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.3" data-path="models.html">
            
                <a href="models.html">
            
                    
                    15.3：Model类定义
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.4" data-path="globals.html">
            
                <a href="globals.html">
            
                    
                    15.4：全局变量及共享状态
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.5" data-path="network.html">
            
                <a href="network.html">
            
                    
                    15.5：网络请求封装
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="4.1.6" data-path="entry.html">
            
                <a href="entry.html">
            
                    
                    15.6：App入口及首页
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.7" data-path="login_page.html">
            
                <a href="login_page.html">
            
                    
                    15.7：登录页
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="4.1.8" data-path="language_and_theme_setting.html">
            
                <a href="language_and_theme_setting.html">
            
                    
                    15.8：多语言和多主题
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            本书使用 GitBook 发布
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    
    <a class="btn pull-right" aria-label="GitHub">
        <i class="fa fa-edit" title="编辑本文"></i>
    </a>
    <a class="btn pull-right" aria-label="GitHub" href="https://github.com/flutterchina/flutter-in-action">
        <i class="fa fa-github" title="查看本书开源项目"></i>
    </a>
    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >15.6：App入口及首页</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="156-app&#x5165;&#x53E3;&#x53CA;&#x4E3B;&#x9875;">15.6 APP&#x5165;&#x53E3;&#x53CA;&#x4E3B;&#x9875;</h1>
<p>&#x672C;&#x8282;&#x6765;&#x4ECB;&#x7ECD;&#x4E00;&#x4E0B;APP&#x5165;&#x53E3;&#x53CA;&#x9996;&#x9875;&#x3002;</p>
<h2 id="1561-app&#x5165;&#x53E3;">15.6.1 APP&#x5165;&#x53E3;</h2>
<p><code>main</code>&#x51FD;&#x6570;&#x4E3A;APP&#x5165;&#x53E3;&#x51FD;&#x6570;&#xFF0C;&#x5B9E;&#x73B0;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre class="language-"><code class="lang-dart"><span class="token keyword">void</span> <span class="token function">main</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=</span><span class="token operator">&gt;</span> Global<span class="token punctuation">.</span><span class="token function">init</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">then</span><span class="token punctuation">(</span><span class="token punctuation">(</span>e<span class="token punctuation">)</span> <span class="token operator">=</span><span class="token operator">&gt;</span> <span class="token function">runApp</span><span class="token punctuation">(</span><span class="token function">MyApp</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
</code></pre>
<p>&#x521D;&#x59CB;&#x5316;&#x5B8C;&#x6210;&#x540E;&#x624D;&#x4F1A;&#x52A0;&#x8F7D;UI(<code>MyApp</code>)&#xFF0C;<code>MyApp</code> &#x662F;&#x5E94;&#x7528;&#x7684;&#x5165;&#x53E3;Widget&#xFF0C;&#x5B9E;&#x73B0;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre class="language-"><code class="lang-dart"><span class="token keyword">class</span> <span class="token class-name">MyApp</span> <span class="token keyword">extends</span> <span class="token class-name">StatelessWidget</span> <span class="token punctuation">{</span>
  <span class="token comment">// This widget is the root of your application.</span>
  <span class="token metadata symbol">@override</span>
  Widget <span class="token function">build</span><span class="token punctuation">(</span>BuildContext context<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token function">MultiProvider</span><span class="token punctuation">(</span>
      providers<span class="token punctuation">:</span> <span class="token operator">&lt;</span>SingleChildCloneableWidget<span class="token operator">&gt;</span><span class="token punctuation">[</span>
        ChangeNotifierProvider<span class="token punctuation">.</span><span class="token function">value</span><span class="token punctuation">(</span>value<span class="token punctuation">:</span> <span class="token function">ThemeModel</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
        ChangeNotifierProvider<span class="token punctuation">.</span><span class="token function">value</span><span class="token punctuation">(</span>value<span class="token punctuation">:</span> <span class="token function">UserModel</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
        ChangeNotifierProvider<span class="token punctuation">.</span><span class="token function">value</span><span class="token punctuation">(</span>value<span class="token punctuation">:</span> <span class="token function">LocaleModel</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
      <span class="token punctuation">]</span><span class="token punctuation">,</span>
      child<span class="token punctuation">:</span> Consumer2<span class="token operator">&lt;</span>ThemeModel<span class="token punctuation">,</span> LocaleModel<span class="token operator">&gt;</span><span class="token punctuation">(</span>
        builder<span class="token punctuation">:</span> <span class="token punctuation">(</span>BuildContext context<span class="token punctuation">,</span> themeModel<span class="token punctuation">,</span> localeModel<span class="token punctuation">,</span> Widget child<span class="token punctuation">)</span> <span class="token punctuation">{</span>
          <span class="token keyword">return</span> <span class="token function">MaterialApp</span><span class="token punctuation">(</span>
            theme<span class="token punctuation">:</span> <span class="token function">ThemeData</span><span class="token punctuation">(</span>
              primarySwatch<span class="token punctuation">:</span> themeModel<span class="token punctuation">.</span>theme<span class="token punctuation">,</span>
            <span class="token punctuation">)</span><span class="token punctuation">,</span>
            onGenerateTitle<span class="token punctuation">:</span> <span class="token punctuation">(</span>context<span class="token punctuation">)</span><span class="token punctuation">{</span>
              <span class="token keyword">return</span> GmLocalizations<span class="token punctuation">.</span><span class="token function">of</span><span class="token punctuation">(</span>context<span class="token punctuation">)</span><span class="token punctuation">.</span>title<span class="token punctuation">;</span>
            <span class="token punctuation">}</span><span class="token punctuation">,</span>
            home<span class="token punctuation">:</span> <span class="token function">HomeRoute</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token comment">//&#x5E94;&#x7528;&#x4E3B;&#x9875;</span>
            locale<span class="token punctuation">:</span> localeModel<span class="token punctuation">.</span><span class="token function">getLocale</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
            <span class="token comment">//&#x6211;&#x4EEC;&#x53EA;&#x652F;&#x6301;&#x7F8E;&#x56FD;&#x82F1;&#x8BED;&#x548C;&#x4E2D;&#x6587;&#x7B80;&#x4F53;</span>
            supportedLocales<span class="token punctuation">:</span> <span class="token punctuation">[</span>
              <span class="token keyword">const</span> <span class="token function">Locale</span><span class="token punctuation">(</span><span class="token string">&apos;en&apos;</span><span class="token punctuation">,</span> <span class="token string">&apos;US&apos;</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token comment">// &#x7F8E;&#x56FD;&#x82F1;&#x8BED;</span>
              <span class="token keyword">const</span> <span class="token function">Locale</span><span class="token punctuation">(</span><span class="token string">&apos;zh&apos;</span><span class="token punctuation">,</span> <span class="token string">&apos;CN&apos;</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token comment">// &#x4E2D;&#x6587;&#x7B80;&#x4F53;</span>
              <span class="token comment">//&#x5176;&#x5B83;Locales</span>
            <span class="token punctuation">]</span><span class="token punctuation">,</span>
            localizationsDelegates<span class="token punctuation">:</span> <span class="token punctuation">[</span>
              <span class="token comment">// &#x672C;&#x5730;&#x5316;&#x7684;&#x4EE3;&#x7406;&#x7C7B;</span>
              GlobalMaterialLocalizations<span class="token punctuation">.</span>delegate<span class="token punctuation">,</span>
              GlobalWidgetsLocalizations<span class="token punctuation">.</span>delegate<span class="token punctuation">,</span>
              <span class="token function">GmLocalizationsDelegate</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
            <span class="token punctuation">]</span><span class="token punctuation">,</span>
            localeResolutionCallback<span class="token punctuation">:</span>
                <span class="token punctuation">(</span>Locale _locale<span class="token punctuation">,</span> Iterable<span class="token operator">&lt;</span>Locale<span class="token operator">&gt;</span> supportedLocales<span class="token punctuation">)</span> <span class="token punctuation">{</span>
              <span class="token keyword">if</span> <span class="token punctuation">(</span>localeModel<span class="token punctuation">.</span><span class="token function">getLocale</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">!=</span> <span class="token keyword">null</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                <span class="token comment">//&#x5982;&#x679C;&#x5DF2;&#x7ECF;&#x9009;&#x5B9A;&#x8BED;&#x8A00;&#xFF0C;&#x5219;&#x4E0D;&#x8DDF;&#x968F;&#x7CFB;&#x7EDF;</span>
                <span class="token keyword">return</span> localeModel<span class="token punctuation">.</span><span class="token function">getLocale</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
              <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span>

                Locale locale<span class="token punctuation">;</span>
                <span class="token comment">//APP&#x8BED;&#x8A00;&#x8DDF;&#x968F;&#x7CFB;&#x7EDF;&#x8BED;&#x8A00;&#xFF0C;&#x5982;&#x679C;&#x7CFB;&#x7EDF;&#x8BED;&#x8A00;&#x4E0D;&#x662F;&#x4E2D;&#x6587;&#x7B80;&#x4F53;&#x6216;&#x7F8E;&#x56FD;&#x82F1;&#x8BED;&#xFF0C;</span>
                <span class="token comment">//&#x5219;&#x9ED8;&#x8BA4;&#x4F7F;&#x7528;&#x7F8E;&#x56FD;&#x82F1;&#x8BED;</span>
                <span class="token keyword">if</span> <span class="token punctuation">(</span>supportedLocales<span class="token punctuation">.</span><span class="token function">contains</span><span class="token punctuation">(</span>_locale<span class="token punctuation">)</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                  locale<span class="token operator">=</span> _locale<span class="token punctuation">;</span>
                <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span>
                  locale<span class="token operator">=</span> <span class="token function">Locale</span><span class="token punctuation">(</span><span class="token string">&apos;en&apos;</span><span class="token punctuation">,</span> <span class="token string">&apos;US&apos;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
                <span class="token punctuation">}</span>
                <span class="token keyword">return</span> locale<span class="token punctuation">;</span>
              <span class="token punctuation">}</span>
            <span class="token punctuation">}</span><span class="token punctuation">,</span>
            <span class="token comment">// &#x6CE8;&#x518C;&#x547D;&#x540D;&#x8DEF;&#x7531;&#x8868;</span>
            routes<span class="token punctuation">:</span> <span class="token operator">&lt;</span>String<span class="token punctuation">,</span> WidgetBuilder<span class="token operator">&gt;</span><span class="token punctuation">{</span>
              <span class="token string">&quot;login&quot;</span><span class="token punctuation">:</span> <span class="token punctuation">(</span>context<span class="token punctuation">)</span> <span class="token operator">=</span><span class="token operator">&gt;</span> <span class="token function">LoginRoute</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
              <span class="token string">&quot;themes&quot;</span><span class="token punctuation">:</span> <span class="token punctuation">(</span>context<span class="token punctuation">)</span> <span class="token operator">=</span><span class="token operator">&gt;</span> <span class="token function">ThemeChangeRoute</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
              <span class="token string">&quot;language&quot;</span><span class="token punctuation">:</span> <span class="token punctuation">(</span>context<span class="token punctuation">)</span> <span class="token operator">=</span><span class="token operator">&gt;</span> <span class="token function">LanguageRoute</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
            <span class="token punctuation">}</span><span class="token punctuation">,</span>
          <span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span><span class="token punctuation">,</span>
      <span class="token punctuation">)</span><span class="token punctuation">,</span>
    <span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<p>&#x5728;&#x4E0A;&#x9762;&#x7684;&#x4EE3;&#x7801;&#x4E2D;&#xFF1A;</p>
<ol>
<li>&#x6211;&#x4EEC;&#x7684;&#x6839;widget&#x662F;<code>MultiProvider</code>&#xFF0C;&#x5B83;&#x5C06;&#x4E3B;&#x9898;&#x3001;&#x7528;&#x6237;&#x3001;&#x8BED;&#x8A00;&#x4E09;&#x79CD;&#x72B6;&#x6001;&#x7ED1;&#x5B9A;&#x5230;&#x4E86;&#x5E94;&#x7528;&#x7684;&#x6839;&#x4E0A;&#xFF0C;&#x5982;&#x6B64;&#x4E00;&#x6765;&#xFF0C;&#x4EFB;&#x4F55;&#x8DEF;&#x7531;&#x4E2D;&#x90FD;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;<code>Provider.of()</code>&#x6765;&#x83B7;&#x53D6;&#x8FD9;&#x4E9B;&#x72B6;&#x6001;&#xFF0C;&#x4E5F;&#x5C31;&#x662F;&#x8BF4;&#x8FD9;&#x4E09;&#x79CD;&#x72B6;&#x6001;&#x662F;&#x5168;&#x5C40;&#x5171;&#x4EAB;&#x7684;&#xFF01;</li>
<li><code>HomeRoute</code>&#x662F;&#x5E94;&#x7528;&#x7684;&#x4E3B;&#x9875;&#x3002;</li>
<li>&#x5728;&#x6784;&#x5EFA;<code>MaterialApp</code>&#x65F6;&#xFF0C;&#x6211;&#x4EEC;&#x914D;&#x7F6E;&#x4E86;APP&#x652F;&#x6301;&#x7684;&#x8BED;&#x8A00;&#x5217;&#x8868;&#xFF0C;&#x4EE5;&#x53CA;&#x76D1;&#x542C;&#x4E86;&#x7CFB;&#x7EDF;&#x8BED;&#x8A00;&#x6539;&#x53D8;&#x4E8B;&#x4EF6;&#xFF1B;&#x53E6;&#x5916;<code>MaterialApp</code>&#x6D88;&#x8D39;&#xFF08;&#x4F9D;&#x8D56;&#xFF09;&#x4E86;<code>ThemeModel</code>&#x548C;<code>LocaleModel</code>&#xFF0C;&#x6240;&#x4EE5;&#x5F53;APP&#x4E3B;&#x9898;&#x6216;&#x8BED;&#x8A00;&#x6539;&#x53D8;&#x65F6;<code>MaterialApp</code>&#x4F1A;&#x91CD;&#x65B0;&#x6784;&#x5EFA;</li>
<li>&#x6211;&#x4EEC;&#x6CE8;&#x518C;&#x4E86;&#x547D;&#x540D;&#x8DEF;&#x7531;&#x8868;&#xFF0C;&#x4EE5;&#x4FBF;&#x5728;APP&#x4E2D;&#x53EF;&#x4EE5;&#x76F4;&#x63A5;&#x901A;&#x8FC7;&#x8DEF;&#x7531;&#x540D;&#x8DF3;&#x8F6C;&#x3002;</li>
<li>&#x4E3A;&#x4E86;&#x652F;&#x6301;&#x591A;&#x8BED;&#x8A00;&#xFF08;&#x672C;APP&#x4E2D;&#x6211;&#x4EEC;&#x652F;&#x6301;&#x7F8E;&#x56FD;&#x82F1;&#x8BED;&#x548C;&#x4E2D;&#x6587;&#x7B80;&#x4F53;&#x4E24;&#x79CD;&#x8BED;&#x8A00;&#xFF09;&#x6211;&#x4EEC;&#x5B9E;&#x73B0;&#x4E86;&#x4E00;&#x4E2A;<code>GmLocalizationsDelegate</code>&#xFF0C;&#x5B50;Widget&#x4E2D;&#x90FD;&#x53EF;&#x4EE5;&#x901A;&#x8FC7;<code>GmLocalizations</code>&#x6765;&#x52A8;&#x6001;&#x83B7;&#x53D6;APP&#x5F53;&#x524D;&#x8BED;&#x8A00;&#x5BF9;&#x5E94;&#x7684;&#x6587;&#x6848;&#x3002;&#x5173;&#x4E8E;<code>GmLocalizationsDelegate</code>&#x548C;<code>GmLocalizations</code>&#x7684;&#x5B9E;&#x73B0;&#x65B9;&#x5F0F;&#x8BFB;&#x8005;&#x53EF;&#x4EE5;&#x53C2;&#x8003;&#x201C;&#x56FD;&#x9645;&#x5316;&#x201D;&#x4E00;&#x7AE0;&#x4E2D;&#x7684;&#x4ECB;&#x7ECD;&#xFF0C;&#x6B64;&#x5904;&#x4E0D;&#x518D;&#x8D58;&#x8FF0;&#x3002;</li>
</ol>
<h2 id="1562-&#x4E3B;&#x9875;">15.6.2 &#x4E3B;&#x9875;</h2>
<p>&#x4E3A;&#x4E86;&#x7B80;&#x5355;&#x8D77;&#x89C1;&#xFF0C;&#x5F53;APP&#x542F;&#x52A8;&#x540E;&#xFF0C;&#x5982;&#x679C;&#x4E4B;&#x524D;&#x5DF2;&#x767B;&#x5F55;&#x4E86;APP&#xFF0C;&#x5219;&#x663E;&#x793A;&#x8BE5;&#x7528;&#x6237;&#x9879;&#x76EE;&#x5217;&#x8868;&#xFF1B;&#x5982;&#x679C;&#x4E4B;&#x524D;&#x672A;&#x767B;&#x5F55;&#xFF0C;&#x5219;&#x663E;&#x793A;&#x4E00;&#x4E2A;&#x767B;&#x5F55;&#x6309;&#x94AE;&#xFF0C;&#x70B9;&#x51FB;&#x540E;&#x8DF3;&#x8F6C;&#x5230;&#x767B;&#x5F55;&#x9875;&#x3002;&#x53E6;&#x5916;&#xFF0C;&#x6211;&#x4EEC;&#x5B9E;&#x73B0;&#x4E00;&#x4E2A;&#x62BD;&#x5C49;&#x83DC;&#x5355;&#xFF0C;&#x91CC;&#x9762;&#x5305;&#x542B;&#x5F53;&#x524D;&#x7528;&#x6237;&#x5934;&#x50CF;&#x53CA;APP&#x7684;&#x83DC;&#x5355;&#x3002;&#x4E0B;&#x9762;&#x6211;&#x4EEC;&#x5148;&#x770B;&#x770B;&#x8981;&#x5B9E;&#x73B0;&#x7684;&#x6548;&#x679C;&#xFF0C;&#x5982;&#x56FE;15-1&#x3001;15-2&#x6240;&#x793A;&#xFF1A;</p>
<p><img src="https://cdn.jsdelivr.net/gh/flutterchina/flutter-in-action/docs/imgs/15-1.png" alt="15-1"><img src="https://cdn.jsdelivr.net/gh/flutterchina/flutter-in-action/docs/imgs/15-2.png" alt="15-2"></p>
<p>&#x6211;&#x4EEC;&#x5728;&#x201C;lib/routes&#x201D;&#x4E0B;&#x521B;&#x5EFA;&#x4E00;&#x4E2A;&#x201C;home_page.dart&#x201D;&#x6587;&#x4EF6;&#xFF0C;&#x5B9E;&#x73B0;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre class="language-"><code class="lang-dart"><span class="token keyword">class</span> <span class="token class-name">HomeRoute</span> <span class="token keyword">extends</span> <span class="token class-name">StatefulWidget</span> <span class="token punctuation">{</span>
  <span class="token metadata symbol">@override</span>
  _HomeRouteState <span class="token function">createState</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=</span><span class="token operator">&gt;</span> <span class="token function">_HomeRouteState</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token keyword">class</span> <span class="token class-name">_HomeRouteState</span> <span class="token keyword">extends</span> <span class="token class-name">State</span><span class="token operator">&lt;</span>HomeRoute<span class="token operator">&gt;</span> <span class="token punctuation">{</span>
  <span class="token metadata symbol">@override</span>
  Widget <span class="token function">build</span><span class="token punctuation">(</span>BuildContext context<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token function">Scaffold</span><span class="token punctuation">(</span>
      appBar<span class="token punctuation">:</span> <span class="token function">AppBar</span><span class="token punctuation">(</span>
        title<span class="token punctuation">:</span> <span class="token function">Text</span><span class="token punctuation">(</span>GmLocalizations<span class="token punctuation">.</span><span class="token function">of</span><span class="token punctuation">(</span>context<span class="token punctuation">)</span><span class="token punctuation">.</span>home<span class="token punctuation">)</span><span class="token punctuation">,</span>
      <span class="token punctuation">)</span><span class="token punctuation">,</span>
      body<span class="token punctuation">:</span> <span class="token function">_buildBody</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token comment">// &#x6784;&#x5EFA;&#x4E3B;&#x9875;&#x9762;</span>
      drawer<span class="token punctuation">:</span> <span class="token function">MyDrawer</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token comment">//&#x62BD;&#x5C49;&#x83DC;&#x5355;</span>
    <span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>
  <span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token punctuation">.</span><span class="token comment">// &#x7701;&#x7565;</span>
<span class="token punctuation">}</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x4E2D;&#xFF0C;&#x4E3B;&#x9875;&#x7684;&#x6807;&#x9898;&#xFF08;title&#xFF09;&#x6211;&#x4EEC;&#x662F;&#x901A;&#x8FC7;<code>GmLocalizations.of(context).home</code>&#x6765;&#x83B7;&#x5F97;&#xFF0C;<code>GmLocalizations</code>&#x662F;&#x6211;&#x4EEC;&#x63D0;&#x4F9B;&#x7684;&#x4E00;&#x4E2A;<code>Localizations</code>&#x7C7B;&#xFF0C;&#x7528;&#x4E8E;&#x652F;&#x6301;&#x591A;&#x8BED;&#x8A00;&#xFF0C;&#x56E0;&#x6B64;&#x5F53;APP&#x8BED;&#x8A00;&#x6539;&#x53D8;&#x65F6;&#xFF0C;&#x51E1;&#x662F;&#x4F7F;&#x7528;<code>GmLocalizations</code>&#x52A8;&#x6001;&#x83B7;&#x53D6;&#x7684;&#x6587;&#x6848;&#x90FD;&#x4F1A;&#x662F;&#x76F8;&#x5E94;&#x8BED;&#x8A00;&#x7684;&#x6587;&#x6848;&#xFF0C;&#x8FD9;&#x5728;&#x524D;&#x9762;&#x201C;&#x56FD;&#x9645;&#x5316;&#x201D;&#x4E00;&#x7AE0;&#x4E2D;&#x5DF2;&#x7ECF;&#x4ECB;&#x7ECD;&#x8FC7;&#xFF0C;&#x8BFB;&#x8005;&#x53EF;&#x4EE5;&#x524D;&#x7FFB;&#x67E5;&#x9605;&#x3002;</p>
<p>&#x6211;&#x4EEC;&#x901A;&#x8FC7; <code>_buildBody()</code>&#x65B9;&#x6CD5;&#x6765;&#x6784;&#x5EFA;&#x4E3B;&#x9875;&#x5185;&#x5BB9;&#xFF0C;<code>_buildBody()</code>&#x65B9;&#x6CD5;&#x5B9E;&#x73B0;&#x4EE3;&#x7801;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre class="language-"><code class="lang-dart">  Widget <span class="token function">_buildBody</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    UserModel userModel <span class="token operator">=</span> Provider<span class="token punctuation">.</span>of<span class="token operator">&lt;</span>UserModel<span class="token operator">&gt;</span><span class="token punctuation">(</span>context<span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token operator">!</span>userModel<span class="token punctuation">.</span>isLogin<span class="token punctuation">)</span> <span class="token punctuation">{</span>
      <span class="token comment">//&#x7528;&#x6237;&#x672A;&#x767B;&#x5F55;&#xFF0C;&#x663E;&#x793A;&#x767B;&#x5F55;&#x6309;&#x94AE;</span>
      <span class="token keyword">return</span> <span class="token function">Center</span><span class="token punctuation">(</span>
        child<span class="token punctuation">:</span> <span class="token function">RaisedButton</span><span class="token punctuation">(</span>
          child<span class="token punctuation">:</span> <span class="token function">Text</span><span class="token punctuation">(</span>GmLocalizations<span class="token punctuation">.</span><span class="token function">of</span><span class="token punctuation">(</span>context<span class="token punctuation">)</span><span class="token punctuation">.</span>login<span class="token punctuation">)</span><span class="token punctuation">,</span>
          onPressed<span class="token punctuation">:</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=</span><span class="token operator">&gt;</span> Navigator<span class="token punctuation">.</span><span class="token function">of</span><span class="token punctuation">(</span>context<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">pushNamed</span><span class="token punctuation">(</span><span class="token string">&quot;login&quot;</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
        <span class="token punctuation">)</span><span class="token punctuation">,</span>
      <span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span> <span class="token keyword">else</span> <span class="token punctuation">{</span>
      <span class="token comment">//&#x5DF2;&#x767B;&#x5F55;&#xFF0C;&#x5219;&#x5C55;&#x793A;&#x9879;&#x76EE;&#x5217;&#x8868;</span>
      <span class="token keyword">return</span> InfiniteListView<span class="token operator">&lt;</span>Repo<span class="token operator">&gt;</span><span class="token punctuation">(</span>
        onRetrieveData<span class="token punctuation">:</span> <span class="token punctuation">(</span>int page<span class="token punctuation">,</span> List<span class="token operator">&lt;</span>Repo<span class="token operator">&gt;</span> items<span class="token punctuation">,</span> bool refresh<span class="token punctuation">)</span> <span class="token keyword">async</span> <span class="token punctuation">{</span>
          <span class="token keyword">var</span> data <span class="token operator">=</span> <span class="token keyword">await</span> <span class="token function">Git</span><span class="token punctuation">(</span>context<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">getRepos</span><span class="token punctuation">(</span>
            refresh<span class="token punctuation">:</span> refresh<span class="token punctuation">,</span>
            queryParameters<span class="token punctuation">:</span> <span class="token punctuation">{</span>
              <span class="token string">&apos;page&apos;</span><span class="token punctuation">:</span> page<span class="token punctuation">,</span>
              <span class="token string">&apos;page_size&apos;</span><span class="token punctuation">:</span> <span class="token number">20</span><span class="token punctuation">,</span>
            <span class="token punctuation">}</span><span class="token punctuation">,</span>
          <span class="token punctuation">)</span><span class="token punctuation">;</span>
          <span class="token comment">//&#x628A;&#x8BF7;&#x6C42;&#x5230;&#x7684;&#x65B0;&#x6570;&#x636E;&#x6DFB;&#x52A0;&#x5230;items&#x4E2D;</span>
          items<span class="token punctuation">.</span><span class="token function">addAll</span><span class="token punctuation">(</span>data<span class="token punctuation">)</span><span class="token punctuation">;</span> 
          <span class="token comment">// &#x5982;&#x679C;&#x63A5;&#x53E3;&#x8FD4;&#x56DE;&#x7684;&#x6570;&#x91CF;&#x7B49;&#x4E8E;&apos;page_size&apos;&#xFF0C;&#x5219;&#x8BA4;&#x4E3A;&#x8FD8;&#x6709;&#x6570;&#x636E;&#xFF0C;&#x53CD;&#x4E4B;&#x5219;&#x8BA4;&#x4E3A;&#x6700;&#x540E;&#x4E00;&#x9875;</span>
          <span class="token keyword">return</span> data<span class="token punctuation">.</span>length<span class="token operator">==</span><span class="token number">20</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span><span class="token punctuation">,</span>
        itemBuilder<span class="token punctuation">:</span> <span class="token punctuation">(</span>List list<span class="token punctuation">,</span> int index<span class="token punctuation">,</span> BuildContext ctx<span class="token punctuation">)</span> <span class="token punctuation">{</span>
          <span class="token comment">// &#x9879;&#x76EE;&#x4FE1;&#x606F;&#x5217;&#x8868;&#x9879;</span>
          <span class="token keyword">return</span> <span class="token function">RepoItem</span><span class="token punctuation">(</span>list<span class="token punctuation">[</span>index<span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token punctuation">}</span><span class="token punctuation">,</span>
      <span class="token punctuation">)</span><span class="token punctuation">;</span>
    <span class="token punctuation">}</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x6CE8;&#x91CA;&#x5F88;&#x6E05;&#x695A;&#xFF1A;&#x5982;&#x679C;&#x7528;&#x6237;&#x672A;&#x767B;&#x5F55;&#xFF0C;&#x663E;&#x793A;&#x767B;&#x5F55;&#x6309;&#x94AE;&#xFF1B;&#x5982;&#x679C;&#x7528;&#x6237;&#x5DF2;&#x767B;&#x5F55;&#xFF0C;&#x5219;&#x5C55;&#x793A;&#x9879;&#x76EE;&#x5217;&#x8868;&#x3002;&#x8FD9;&#x91CC;&#x9879;&#x76EE;&#x5217;&#x8868;&#x4F7F;&#x7528;&#x4E86;<code>InfiniteListView</code> Widget&#xFF0C;&#x5B83;&#x662F;flukit package&#x4E2D;&#x63D0;&#x4F9B;&#x7684;&#x3002;<code>InfiniteListView</code>&#x540C;&#x65F6;&#x652F;&#x6301;&#x4E86;&#x4E0B;&#x62C9;&#x5237;&#x65B0;&#x548C;&#x4E0A;&#x62C9;&#x52A0;&#x8F7D;&#x66F4;&#x591A;&#x4E24;&#x79CD;&#x529F;&#x80FD;&#x3002;<code>onRetrieveData</code> &#x4E3A;&#x6570;&#x636E;&#x83B7;&#x53D6;&#x56DE;&#x8C03;&#xFF0C;&#x8BE5;&#x56DE;&#x8C03;&#x51FD;&#x6570;&#x63A5;&#x6536;&#x4E09;&#x4E2A;&#x53C2;&#x6570;&#xFF1A;</p>
<table>
<thead>
<tr>
<th>&#x53C2;&#x6570;&#x540D;</th>
<th>&#x7C7B;&#x578B;</th>
<th>&#x89E3;&#x91CA;</th>
</tr>
</thead>
<tbody>
<tr>
<td>page</td>
<td>int</td>
<td>&#x5F53;&#x524D;&#x9875;&#x53F7;</td>
</tr>
<tr>
<td>items</td>
<td>List<t></t></td>
<td>&#x4FDD;&#x5B58;&#x5F53;&#x524D;&#x5217;&#x8868;&#x6570;&#x636E;&#x7684;List</td>
</tr>
<tr>
<td>refresh</td>
<td>bool</td>
<td>&#x662F;&#x5426;&#x662F;&#x4E0B;&#x62C9;&#x5237;&#x65B0;&#x89E6;&#x53D1;</td>
</tr>
</tbody>
</table>
<p>&#x8FD4;&#x56DE;&#x503C;&#x7C7B;&#x578B;&#x4E3A;<code>bool</code>&#xFF0C;&#x4E3A;<code>true</code>&#x65F6;&#x8868;&#x793A;&#x8FD8;&#x6709;&#x6570;&#x636E;&#xFF0C;&#x4E3A;<code>false</code>&#x65F6;&#x5219;&#x8868;&#x793A;&#x540E;&#x7EED;&#x6CA1;&#x6709;&#x6570;&#x636E;&#x4E86;&#x3002;<code>onRetrieveData</code> &#x56DE;&#x8C03;&#x4E2D;&#x6211;&#x4EEC;&#x8C03;&#x7528;<code>Git(context).getRepos(...)</code>&#x6765;&#x83B7;&#x53D6;&#x7528;&#x6237;&#x9879;&#x76EE;&#x5217;&#x8868;&#xFF0C;&#x540C;&#x65F6;&#x6307;&#x5B9A;&#x6BCF;&#x6B21;&#x8BF7;&#x6C42;&#x83B7;&#x53D6;20&#x6761;&#x3002;&#x5F53;&#x83B7;&#x53D6;&#x6210;&#x529F;&#x65F6;&#xFF0C;&#x9996;&#x5148;&#x8981;&#x5C06;&#x65B0;&#x83B7;&#x53D6;&#x7684;&#x9879;&#x76EE;&#x6570;&#x636E;&#x6DFB;&#x52A0;&#x5230;<code>items</code>&#x4E2D;&#xFF0C;&#x7136;&#x540E;&#x6839;&#x636E;&#x672C;&#x6B21;&#x8BF7;&#x6C42;&#x7684;&#x9879;&#x76EE;&#x6761;&#x6570;&#x662F;&#x5426;&#x7B49;&#x4E8E;&#x671F;&#x671B;&#x7684;20&#x6761;&#x6765;&#x5224;&#x65AD;&#x8FD8;&#x6709;&#x6CA1;&#x6709;&#x66F4;&#x591A;&#x7684;&#x6570;&#x636E;&#x3002;&#x5728;&#x6B64;&#x9700;&#x8981;&#x6CE8;&#x610F;&#xFF0C;<code>Git(context).getRepos(&#x2026;)</code>&#x65B9;&#x6CD5;&#x4E2D;&#x9700;&#x8981;<code>refresh</code>&#x53C2;&#x6570;&#x6765;&#x5224;&#x65AD;&#x662F;&#x5426;&#x4F7F;&#x7528;&#x7F13;&#x5B58;&#x3002;</p>
<p><code>itemBuilder</code>&#x4E3A;&#x5217;&#x8868;&#x9879;&#x7684;builder&#xFF0C;&#x6211;&#x4EEC;&#x9700;&#x8981;&#x5728;&#x8BE5;&#x56DE;&#x8C03;&#x4E2D;&#x6784;&#x5EFA;&#x6BCF;&#x4E00;&#x4E2A;&#x5217;&#x8868;&#x9879;Widget&#x3002;&#x7531;&#x4E8E;&#x5217;&#x8868;&#x9879;&#x6784;&#x5EFA;&#x903B;&#x8F91;&#x8F83;&#x590D;&#x6742;&#xFF0C;&#x6211;&#x4EEC;&#x5355;&#x72EC;&#x5C01;&#x88C5;&#x4E00;&#x4E2A;<code>RepoItem</code> Widget &#x4E13;&#x95E8;&#x7528;&#x4E8E;&#x6784;&#x5EFA;&#x5217;&#x8868;&#x9879;UI&#x3002;<code>RepoItem</code> &#x5B9E;&#x73B0;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre class="language-"><code class="lang-dart"><span class="token keyword">import</span> <span class="token string">&apos;../index.dart&apos;</span><span class="token punctuation">;</span>

<span class="token keyword">class</span> <span class="token class-name">RepoItem</span> <span class="token keyword">extends</span> <span class="token class-name">StatefulWidget</span> <span class="token punctuation">{</span>
  <span class="token comment">// &#x5C06;`repo.id`&#x4F5C;&#x4E3A;RepoItem&#x7684;&#x9ED8;&#x8BA4;key</span>
  <span class="token function">RepoItem</span><span class="token punctuation">(</span><span class="token keyword">this</span><span class="token punctuation">.</span>repo<span class="token punctuation">)</span> <span class="token punctuation">:</span> <span class="token keyword">super</span><span class="token punctuation">(</span>key<span class="token punctuation">:</span> <span class="token function">ValueKey</span><span class="token punctuation">(</span>repo<span class="token punctuation">.</span>id<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>

  <span class="token keyword">final</span> Repo repo<span class="token punctuation">;</span>

  <span class="token metadata symbol">@override</span>
  _RepoItemState <span class="token function">createState</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=</span><span class="token operator">&gt;</span> <span class="token function">_RepoItemState</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>

<span class="token keyword">class</span> <span class="token class-name">_RepoItemState</span> <span class="token keyword">extends</span> <span class="token class-name">State</span><span class="token operator">&lt;</span>RepoItem<span class="token operator">&gt;</span> <span class="token punctuation">{</span>
  <span class="token metadata symbol">@override</span>
  Widget <span class="token function">build</span><span class="token punctuation">(</span>BuildContext context<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">var</span> subtitle<span class="token punctuation">;</span>
    <span class="token keyword">return</span> <span class="token function">Padding</span><span class="token punctuation">(</span>
      padding<span class="token punctuation">:</span> <span class="token keyword">const</span> EdgeInsets<span class="token punctuation">.</span><span class="token function">only</span><span class="token punctuation">(</span>top<span class="token punctuation">:</span> <span class="token number">8.0</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
      child<span class="token punctuation">:</span> <span class="token function">Material</span><span class="token punctuation">(</span>
        color<span class="token punctuation">:</span> Colors<span class="token punctuation">.</span>white<span class="token punctuation">,</span>
        shape<span class="token punctuation">:</span> <span class="token function">BorderDirectional</span><span class="token punctuation">(</span>
          bottom<span class="token punctuation">:</span> <span class="token function">BorderSide</span><span class="token punctuation">(</span>
            color<span class="token punctuation">:</span> Theme<span class="token punctuation">.</span><span class="token function">of</span><span class="token punctuation">(</span>context<span class="token punctuation">)</span><span class="token punctuation">.</span>dividerColor<span class="token punctuation">,</span>
            width<span class="token punctuation">:</span> <span class="token number">.5</span><span class="token punctuation">,</span>
          <span class="token punctuation">)</span><span class="token punctuation">,</span>
        <span class="token punctuation">)</span><span class="token punctuation">,</span>
        child<span class="token punctuation">:</span> <span class="token function">Padding</span><span class="token punctuation">(</span>
          padding<span class="token punctuation">:</span> <span class="token keyword">const</span> EdgeInsets<span class="token punctuation">.</span><span class="token function">only</span><span class="token punctuation">(</span>top<span class="token punctuation">:</span> <span class="token number">0.0</span><span class="token punctuation">,</span> bottom<span class="token punctuation">:</span> <span class="token number">16</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
          child<span class="token punctuation">:</span> <span class="token function">Column</span><span class="token punctuation">(</span>
            crossAxisAlignment<span class="token punctuation">:</span> CrossAxisAlignment<span class="token punctuation">.</span>start<span class="token punctuation">,</span>
            children<span class="token punctuation">:</span> <span class="token operator">&lt;</span>Widget<span class="token operator">&gt;</span><span class="token punctuation">[</span>
              <span class="token function">ListTile</span><span class="token punctuation">(</span>
                dense<span class="token punctuation">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span>
                leading<span class="token punctuation">:</span> <span class="token function">gmAvatar</span><span class="token punctuation">(</span>
                  <span class="token comment">//&#x9879;&#x76EE;owner&#x5934;&#x50CF;</span>
                  widget<span class="token punctuation">.</span>repo<span class="token punctuation">.</span>owner<span class="token punctuation">.</span>avatar_url<span class="token punctuation">,</span>
                  width<span class="token punctuation">:</span> <span class="token number">24.0</span><span class="token punctuation">,</span>
                  borderRadius<span class="token punctuation">:</span> BorderRadius<span class="token punctuation">.</span><span class="token function">circular</span><span class="token punctuation">(</span><span class="token number">12</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
                <span class="token punctuation">)</span><span class="token punctuation">,</span>
                title<span class="token punctuation">:</span> <span class="token function">Text</span><span class="token punctuation">(</span>
                  widget<span class="token punctuation">.</span>repo<span class="token punctuation">.</span>owner<span class="token punctuation">.</span>login<span class="token punctuation">,</span>
                  textScaleFactor<span class="token punctuation">:</span> <span class="token number">.9</span><span class="token punctuation">,</span>
                <span class="token punctuation">)</span><span class="token punctuation">,</span>
                subtitle<span class="token punctuation">:</span> subtitle<span class="token punctuation">,</span>
                trailing<span class="token punctuation">:</span> <span class="token function">Text</span><span class="token punctuation">(</span>widget<span class="token punctuation">.</span>repo<span class="token punctuation">.</span>language <span class="token operator">?</span><span class="token operator">?</span> <span class="token string">&quot;&quot;</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
              <span class="token punctuation">)</span><span class="token punctuation">,</span>
              <span class="token comment">// &#x6784;&#x5EFA;&#x9879;&#x76EE;&#x6807;&#x9898;&#x548C;&#x7B80;&#x4ECB;</span>
              <span class="token function">Padding</span><span class="token punctuation">(</span>
                padding<span class="token punctuation">:</span> <span class="token keyword">const</span> EdgeInsets<span class="token punctuation">.</span><span class="token function">symmetric</span><span class="token punctuation">(</span>horizontal<span class="token punctuation">:</span> <span class="token number">16.0</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
                child<span class="token punctuation">:</span> <span class="token function">Column</span><span class="token punctuation">(</span>
                  crossAxisAlignment<span class="token punctuation">:</span> CrossAxisAlignment<span class="token punctuation">.</span>start<span class="token punctuation">,</span>
                  children<span class="token punctuation">:</span> <span class="token operator">&lt;</span>Widget<span class="token operator">&gt;</span><span class="token punctuation">[</span>
                    <span class="token function">Text</span><span class="token punctuation">(</span>
                      widget<span class="token punctuation">.</span>repo<span class="token punctuation">.</span>fork
                          <span class="token operator">?</span> widget<span class="token punctuation">.</span>repo<span class="token punctuation">.</span>full_name
                          <span class="token punctuation">:</span> widget<span class="token punctuation">.</span>repo<span class="token punctuation">.</span>name<span class="token punctuation">,</span>
                      style<span class="token punctuation">:</span> <span class="token function">TextStyle</span><span class="token punctuation">(</span>
                        fontSize<span class="token punctuation">:</span> <span class="token number">15</span><span class="token punctuation">,</span>
                        fontWeight<span class="token punctuation">:</span> FontWeight<span class="token punctuation">.</span>bold<span class="token punctuation">,</span>
                        fontStyle<span class="token punctuation">:</span> widget<span class="token punctuation">.</span>repo<span class="token punctuation">.</span>fork
                            <span class="token operator">?</span> FontStyle<span class="token punctuation">.</span>italic
                            <span class="token punctuation">:</span> FontStyle<span class="token punctuation">.</span>normal<span class="token punctuation">,</span>
                      <span class="token punctuation">)</span><span class="token punctuation">,</span>
                    <span class="token punctuation">)</span><span class="token punctuation">,</span>
                    <span class="token function">Padding</span><span class="token punctuation">(</span>
                      padding<span class="token punctuation">:</span> <span class="token keyword">const</span> EdgeInsets<span class="token punctuation">.</span><span class="token function">only</span><span class="token punctuation">(</span>top<span class="token punctuation">:</span> <span class="token number">8</span><span class="token punctuation">,</span> bottom<span class="token punctuation">:</span> <span class="token number">12</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
                      child<span class="token punctuation">:</span> widget<span class="token punctuation">.</span>repo<span class="token punctuation">.</span>description <span class="token operator">==</span> <span class="token keyword">null</span>
                          <span class="token operator">?</span> <span class="token function">Text</span><span class="token punctuation">(</span>
                              GmLocalizations<span class="token punctuation">.</span><span class="token function">of</span><span class="token punctuation">(</span>context<span class="token punctuation">)</span><span class="token punctuation">.</span>noDescription<span class="token punctuation">,</span>
                              style<span class="token punctuation">:</span> <span class="token function">TextStyle</span><span class="token punctuation">(</span>
                                  fontStyle<span class="token punctuation">:</span> FontStyle<span class="token punctuation">.</span>italic<span class="token punctuation">,</span>
                                  color<span class="token punctuation">:</span> Colors<span class="token punctuation">.</span>grey<span class="token punctuation">[</span><span class="token number">700</span><span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
                            <span class="token punctuation">)</span>
                          <span class="token punctuation">:</span> <span class="token function">Text</span><span class="token punctuation">(</span>
                              widget<span class="token punctuation">.</span>repo<span class="token punctuation">.</span>description<span class="token punctuation">,</span>
                              maxLines<span class="token punctuation">:</span> <span class="token number">3</span><span class="token punctuation">,</span>
                              style<span class="token punctuation">:</span> <span class="token function">TextStyle</span><span class="token punctuation">(</span>
                                height<span class="token punctuation">:</span> <span class="token number">1.15</span><span class="token punctuation">,</span>
                                color<span class="token punctuation">:</span> Colors<span class="token punctuation">.</span>blueGrey<span class="token punctuation">[</span><span class="token number">700</span><span class="token punctuation">]</span><span class="token punctuation">,</span>
                                fontSize<span class="token punctuation">:</span> <span class="token number">13</span><span class="token punctuation">,</span>
                              <span class="token punctuation">)</span><span class="token punctuation">,</span>
                            <span class="token punctuation">)</span><span class="token punctuation">,</span>
                    <span class="token punctuation">)</span><span class="token punctuation">,</span>
                  <span class="token punctuation">]</span><span class="token punctuation">,</span>
                <span class="token punctuation">)</span><span class="token punctuation">,</span>
              <span class="token punctuation">)</span><span class="token punctuation">,</span>
              <span class="token comment">// &#x6784;&#x5EFA;&#x5361;&#x7247;&#x5E95;&#x90E8;&#x4FE1;&#x606F;</span>
              <span class="token function">_buildBottom</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
            <span class="token punctuation">]</span><span class="token punctuation">,</span>
          <span class="token punctuation">)</span><span class="token punctuation">,</span>
        <span class="token punctuation">)</span><span class="token punctuation">,</span>
      <span class="token punctuation">)</span><span class="token punctuation">,</span>
    <span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>

  <span class="token comment">// &#x6784;&#x5EFA;&#x5361;&#x7247;&#x5E95;&#x90E8;&#x4FE1;&#x606F;</span>
  Widget <span class="token function">_buildBottom</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">const</span> paddingWidth <span class="token operator">=</span> <span class="token number">10</span><span class="token punctuation">;</span>
    <span class="token keyword">return</span> <span class="token function">IconTheme</span><span class="token punctuation">(</span>
      data<span class="token punctuation">:</span> <span class="token function">IconThemeData</span><span class="token punctuation">(</span>
        color<span class="token punctuation">:</span> Colors<span class="token punctuation">.</span>grey<span class="token punctuation">,</span>
        size<span class="token punctuation">:</span> <span class="token number">15</span><span class="token punctuation">,</span>
      <span class="token punctuation">)</span><span class="token punctuation">,</span>
      child<span class="token punctuation">:</span> <span class="token function">DefaultTextStyle</span><span class="token punctuation">(</span>
        style<span class="token punctuation">:</span> <span class="token function">TextStyle</span><span class="token punctuation">(</span>color<span class="token punctuation">:</span> Colors<span class="token punctuation">.</span>grey<span class="token punctuation">,</span> fontSize<span class="token punctuation">:</span> <span class="token number">12</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
        child<span class="token punctuation">:</span> <span class="token function">Padding</span><span class="token punctuation">(</span>
          padding<span class="token punctuation">:</span> <span class="token keyword">const</span> EdgeInsets<span class="token punctuation">.</span><span class="token function">symmetric</span><span class="token punctuation">(</span>horizontal<span class="token punctuation">:</span> <span class="token number">16</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
          child<span class="token punctuation">:</span> <span class="token function">Builder</span><span class="token punctuation">(</span>builder<span class="token punctuation">:</span> <span class="token punctuation">(</span>context<span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token keyword">var</span> children <span class="token operator">=</span> <span class="token operator">&lt;</span>Widget<span class="token operator">&gt;</span><span class="token punctuation">[</span>
              <span class="token function">Icon</span><span class="token punctuation">(</span>Icons<span class="token punctuation">.</span>star<span class="token punctuation">)</span><span class="token punctuation">,</span>
              <span class="token function">Text</span><span class="token punctuation">(</span><span class="token string">&quot; &quot;</span> <span class="token operator">+</span>
                  widget<span class="token punctuation">.</span>repo<span class="token punctuation">.</span>stargazers_count
                      <span class="token punctuation">.</span><span class="token function">toString</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
                      <span class="token punctuation">.</span><span class="token function">padRight</span><span class="token punctuation">(</span>paddingWidth<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
              <span class="token function">Icon</span><span class="token punctuation">(</span>Icons<span class="token punctuation">.</span>info_outline<span class="token punctuation">)</span><span class="token punctuation">,</span>
              <span class="token function">Text</span><span class="token punctuation">(</span><span class="token string">&quot; &quot;</span> <span class="token operator">+</span>
                  widget<span class="token punctuation">.</span>repo<span class="token punctuation">.</span>open_issues_count
                      <span class="token punctuation">.</span><span class="token function">toString</span><span class="token punctuation">(</span><span class="token punctuation">)</span>
                      <span class="token punctuation">.</span><span class="token function">padRight</span><span class="token punctuation">(</span>paddingWidth<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">,</span>

              <span class="token function">Icon</span><span class="token punctuation">(</span>MyIcons<span class="token punctuation">.</span>fork<span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token comment">//&#x6211;&#x4EEC;&#x7684;&#x81EA;&#x5B9A;&#x4E49;&#x56FE;&#x6807;</span>
              <span class="token function">Text</span><span class="token punctuation">(</span>widget<span class="token punctuation">.</span>repo<span class="token punctuation">.</span>forks_count<span class="token punctuation">.</span><span class="token function">toString</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">padRight</span><span class="token punctuation">(</span>paddingWidth<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
            <span class="token punctuation">]</span><span class="token punctuation">;</span>

            <span class="token keyword">if</span> <span class="token punctuation">(</span>widget<span class="token punctuation">.</span>repo<span class="token punctuation">.</span>fork<span class="token punctuation">)</span> <span class="token punctuation">{</span>
              children<span class="token punctuation">.</span><span class="token function">add</span><span class="token punctuation">(</span><span class="token function">Text</span><span class="token punctuation">(</span><span class="token string">&quot;Forked&quot;</span><span class="token punctuation">.</span><span class="token function">padRight</span><span class="token punctuation">(</span>paddingWidth<span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span>

            <span class="token keyword">if</span> <span class="token punctuation">(</span>widget<span class="token punctuation">.</span>repo<span class="token punctuation">.</span>private <span class="token operator">==</span> <span class="token boolean">true</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
              children<span class="token punctuation">.</span><span class="token function">addAll</span><span class="token punctuation">(</span><span class="token operator">&lt;</span>Widget<span class="token operator">&gt;</span><span class="token punctuation">[</span>
                <span class="token function">Icon</span><span class="token punctuation">(</span>Icons<span class="token punctuation">.</span>lock<span class="token punctuation">)</span><span class="token punctuation">,</span>
                <span class="token function">Text</span><span class="token punctuation">(</span><span class="token string">&quot; private&quot;</span><span class="token punctuation">.</span><span class="token function">padRight</span><span class="token punctuation">(</span>paddingWidth<span class="token punctuation">)</span><span class="token punctuation">)</span>
              <span class="token punctuation">]</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
            <span class="token punctuation">}</span>
            <span class="token keyword">return</span> <span class="token function">Row</span><span class="token punctuation">(</span>children<span class="token punctuation">:</span> children<span class="token punctuation">)</span><span class="token punctuation">;</span>
          <span class="token punctuation">}</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
        <span class="token punctuation">)</span><span class="token punctuation">,</span>
      <span class="token punctuation">)</span><span class="token punctuation">,</span>
    <span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<p>&#x4E0A;&#x9762;&#x4EE3;&#x7801;&#x6709;&#x4E24;&#x70B9;&#x9700;&#x8981;&#x6CE8;&#x610F;&#xFF1A;</p>
<ol>
<li><p>&#x5728;&#x6784;&#x5EFA;&#x9879;&#x76EE;&#x62E5;&#x6709;&#x8005;&#x5934;&#x50CF;&#x65F6;&#x8C03;&#x7528;&#x4E86;<code>gmAvatar(&#x2026;)</code>&#x65B9;&#x6CD5;&#xFF0C;&#x8BE5;&#x65B9;&#x6CD5;&#x662F;&#x662F;&#x4E00;&#x4E2A;&#x5168;&#x5C40;&#x5DE5;&#x5177;&#x51FD;&#x6570;&#xFF0C;&#x4E13;&#x95E8;&#x7528;&#x4E8E;&#x83B7;&#x53D6;&#x5934;&#x50CF;&#x56FE;&#x7247;&#xFF0C;&#x5B9E;&#x73B0;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre class="language-"><code class="lang-dart">Widget <span class="token function">gmAvatar</span><span class="token punctuation">(</span>String url<span class="token punctuation">,</span> <span class="token punctuation">{</span>
  double width <span class="token operator">=</span> <span class="token number">30</span><span class="token punctuation">,</span>
  double height<span class="token punctuation">,</span>
  BoxFit fit<span class="token punctuation">,</span>
  BorderRadius borderRadius<span class="token punctuation">,</span>
<span class="token punctuation">}</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
  <span class="token keyword">var</span> placeholder <span class="token operator">=</span> Image<span class="token punctuation">.</span><span class="token function">asset</span><span class="token punctuation">(</span>
      <span class="token string">&quot;imgs/avatar-default.png&quot;</span><span class="token punctuation">,</span> <span class="token comment">//&#x5934;&#x50CF;&#x5360;&#x4F4D;&#x56FE;&#xFF0C;&#x52A0;&#x8F7D;&#x8FC7;&#x7A0B;&#x4E2D;&#x663E;&#x793A;</span>
      width<span class="token punctuation">:</span> width<span class="token punctuation">,</span>
      height<span class="token punctuation">:</span> height
  <span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token keyword">return</span> <span class="token function">ClipRRect</span><span class="token punctuation">(</span>
    borderRadius<span class="token punctuation">:</span> borderRadius <span class="token operator">?</span><span class="token operator">?</span> BorderRadius<span class="token punctuation">.</span><span class="token function">circular</span><span class="token punctuation">(</span><span class="token number">2</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
    child<span class="token punctuation">:</span> <span class="token function">CachedNetworkImage</span><span class="token punctuation">(</span> 
      imageUrl<span class="token punctuation">:</span> url<span class="token punctuation">,</span>
      width<span class="token punctuation">:</span> width<span class="token punctuation">,</span>
      height<span class="token punctuation">:</span> height<span class="token punctuation">,</span>
      fit<span class="token punctuation">:</span> fit<span class="token punctuation">,</span>
      placeholder<span class="token punctuation">:</span> <span class="token punctuation">(</span>context<span class="token punctuation">,</span> url<span class="token punctuation">)</span> <span class="token operator">=</span><span class="token operator">&gt;</span>placeholder<span class="token punctuation">,</span>
      errorWidget<span class="token punctuation">:</span> <span class="token punctuation">(</span>context<span class="token punctuation">,</span> url<span class="token punctuation">,</span> error<span class="token punctuation">)</span> <span class="token operator">=</span><span class="token operator">&gt;</span>placeholder<span class="token punctuation">,</span>
    <span class="token punctuation">)</span><span class="token punctuation">,</span>
  <span class="token punctuation">)</span><span class="token punctuation">;</span>
<span class="token punctuation">}</span>
</code></pre>
<p>&#x4EE3;&#x7801;&#x4E2D;&#x8C03;&#x7528;&#x4E86;<code>CachedNetworkImage</code> &#x662F;cached_network_image&#x5305;&#x4E2D;&#x63D0;&#x4F9B;&#x7684;&#x4E00;&#x4E2A;Widget&#xFF0C;&#x5B83;&#x4E0D;&#x4EC5;&#x53EF;&#x4EE5;&#x5728;&#x56FE;&#x7247;&#x52A0;&#x8F7D;&#x8FC7;&#x7A0B;&#x4E2D;&#x6307;&#x5B9A;&#x4E00;&#x4E2A;&#x5360;&#x4F4D;&#x56FE;&#xFF0C;&#x800C;&#x4E14;&#x8FD8;&#x53EF;&#x4EE5;&#x5BF9;&#x7F51;&#x7EDC;&#x8BF7;&#x6C42;&#x7684;&#x56FE;&#x7247;&#x8FDB;&#x884C;&#x7F13;&#x5B58;&#xFF0C;&#x66F4;&#x591A;&#x8BE6;&#x60C5;&#x8BFB;&#x8005;&#x53EF;&#x4EE5;&#x81EA;&#x884C;&#x67E5;&#x9605;&#x5176;&#x6587;&#x6863;&#x3002;</p>
</li>
<li><p>&#x7531;&#x4E8E;Flutter &#x7684;Material &#x56FE;&#x6807;&#x5E93;&#x4E2D;&#x6CA1;&#x6709;fork&#x56FE;&#x6807;&#xFF0C;&#x6240;&#x4EE5;&#x6211;&#x4EEC;&#x5728;iconfont.cn&#x4E0A;&#x627E;&#x4E86;&#x4E00;&#x4E2A;fork&#x56FE;&#x6807;&#xFF0C;&#x7136;&#x540E;&#x6839;&#x636E;&#x201C;&#x56FE;&#x7247;&#x548C;Icon&#x201D;&#x4E00;&#x8282;&#x4E2D;&#x4ECB;&#x7ECD;&#x7684;&#x4F7F;&#x7528;&#x81EA;&#x5B9A;&#x4E49;&#x5B57;&#x4F53;&#x56FE;&#x6807;&#x7684;&#x65B9;&#x6CD5;&#x96C6;&#x6210;&#x5230;&#x4E86;&#x6211;&#x4EEC;&#x7684;&#x9879;&#x76EE;&#x4E2D;&#x3002;</p>
</li>
</ol>
<h2 id="1563-&#x62BD;&#x5C49;&#x83DC;&#x5355;">15.6.3 &#x62BD;&#x5C49;&#x83DC;&#x5355;</h2>
<p>&#x62BD;&#x5C49;&#x83DC;&#x5355;&#x5206;&#x4E3A;&#x4E24;&#x90E8;&#x5206;&#xFF1A;&#x9876;&#x90E8;&#x5934;&#x50CF;&#x548C;&#x5E95;&#x90E8;&#x529F;&#x80FD;&#x83DC;&#x5355;&#x9879;&#x3002;&#x5F53;&#x7528;&#x6237;&#x672A;&#x767B;&#x5F55;&#xFF0C;&#x5219;&#x62BD;&#x5C49;&#x83DC;&#x5355;&#x9876;&#x90E8;&#x4F1A;&#x663E;&#x793A;&#x4E00;&#x4E2A;&#x9ED8;&#x8BA4;&#x7684;&#x7070;&#x8272;&#x5360;&#x4F4D;&#x56FE;&#xFF0C;&#x82E5;&#x7528;&#x6237;&#x5DF2;&#x767B;&#x5F55;&#xFF0C;&#x5219;&#x4F1A;&#x663E;&#x793A;&#x7528;&#x6237;&#x7684;&#x5934;&#x50CF;&#x3002;&#x62BD;&#x5C49;&#x83DC;&#x5355;&#x5E95;&#x90E8;&#x6709;&#x201C;&#x6362;&#x80A4;&#x201D;&#x548C;&#x201C;&#x8BED;&#x8A00;&#x201D;&#x4E24;&#x4E2A;&#x56FA;&#x5B9A;&#x83DC;&#x5355;&#xFF0C;&#x82E5;&#x7528;&#x6237;&#x5DF2;&#x767B;&#x5F55;&#xFF0C;&#x5219;&#x4F1A;&#x591A;&#x4E00;&#x4E2A;&#x201C;&#x6CE8;&#x9500;&#x201D;&#x83DC;&#x5355;&#x3002;&#x7528;&#x6237;&#x70B9;&#x51FB;&#x201C;&#x6362;&#x80A4;&#x201D;&#x548C;&#x201C;&#x8BED;&#x8A00;&#x201D;&#x4E24;&#x4E2A;&#x83DC;&#x5355;&#x9879;&#xFF0C;&#x4F1A;&#x8FDB;&#x5165;&#x76F8;&#x5E94;&#x7684;&#x8BBE;&#x7F6E;&#x9875;&#x9762;&#x3002;&#x6211;&#x4EEC;&#x7684;&#x62BD;&#x5C49;&#x83DC;&#x5355;&#x6548;&#x679C;&#x5982;&#x56FE;15-3&#x3001;15-4&#x6240;&#x793A;&#xFF1A;</p>
<p><img src="https://cdn.jsdelivr.net/gh/flutterchina/flutter-in-action/docs/imgs/15-3.png" alt="15-3"><img src="https://cdn.jsdelivr.net/gh/flutterchina/flutter-in-action/docs/imgs/15-4.png" alt="15-4"></p>
<p>&#x5B9E;&#x73B0;&#x4EE3;&#x7801;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre class="language-"><code class="lang-dart"><span class="token keyword">class</span> <span class="token class-name">MyDrawer</span> <span class="token keyword">extends</span> <span class="token class-name">StatelessWidget</span> <span class="token punctuation">{</span>
  <span class="token keyword">const</span> <span class="token function">MyDrawer</span><span class="token punctuation">(</span><span class="token punctuation">{</span>
    Key key<span class="token punctuation">,</span>
  <span class="token punctuation">}</span><span class="token punctuation">)</span> <span class="token punctuation">:</span> <span class="token keyword">super</span><span class="token punctuation">(</span>key<span class="token punctuation">:</span> key<span class="token punctuation">)</span><span class="token punctuation">;</span>

  <span class="token metadata symbol">@override</span>
  Widget <span class="token function">build</span><span class="token punctuation">(</span>BuildContext context<span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">return</span> <span class="token function">Drawer</span><span class="token punctuation">(</span>
      <span class="token comment">//&#x79FB;&#x9664;&#x9876;&#x90E8;padding</span>
      child<span class="token punctuation">:</span> MediaQuery<span class="token punctuation">.</span><span class="token function">removePadding</span><span class="token punctuation">(</span>
        context<span class="token punctuation">:</span> context<span class="token punctuation">,</span>
        removeTop<span class="token punctuation">:</span> <span class="token boolean">true</span><span class="token punctuation">,</span>
        child<span class="token punctuation">:</span> <span class="token function">Column</span><span class="token punctuation">(</span>
          crossAxisAlignment<span class="token punctuation">:</span> CrossAxisAlignment<span class="token punctuation">.</span>start<span class="token punctuation">,</span>
          children<span class="token punctuation">:</span> <span class="token operator">&lt;</span>Widget<span class="token operator">&gt;</span><span class="token punctuation">[</span>
            <span class="token function">_buildHeader</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token comment">//&#x6784;&#x5EFA;&#x62BD;&#x5C49;&#x83DC;&#x5355;&#x5934;&#x90E8;</span>
            <span class="token function">Expanded</span><span class="token punctuation">(</span>child<span class="token punctuation">:</span> <span class="token function">_buildMenus</span><span class="token punctuation">(</span><span class="token punctuation">)</span><span class="token punctuation">)</span><span class="token punctuation">,</span> <span class="token comment">//&#x6784;&#x5EFA;&#x529F;&#x80FD;&#x83DC;&#x5355;</span>
          <span class="token punctuation">]</span><span class="token punctuation">,</span>
        <span class="token punctuation">)</span><span class="token punctuation">,</span>
      <span class="token punctuation">)</span><span class="token punctuation">,</span>
    <span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>

  Widget <span class="token function">_buildHeader</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">return</span> Consumer<span class="token operator">&lt;</span>UserModel<span class="token operator">&gt;</span><span class="token punctuation">(</span>
      builder<span class="token punctuation">:</span> <span class="token punctuation">(</span>BuildContext context<span class="token punctuation">,</span> UserModel value<span class="token punctuation">,</span> Widget child<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">return</span> <span class="token function">GestureDetector</span><span class="token punctuation">(</span>
          child<span class="token punctuation">:</span> <span class="token function">Container</span><span class="token punctuation">(</span>
            color<span class="token punctuation">:</span> Theme<span class="token punctuation">.</span><span class="token function">of</span><span class="token punctuation">(</span>context<span class="token punctuation">)</span><span class="token punctuation">.</span>primaryColor<span class="token punctuation">,</span>
            padding<span class="token punctuation">:</span> EdgeInsets<span class="token punctuation">.</span><span class="token function">only</span><span class="token punctuation">(</span>top<span class="token punctuation">:</span> <span class="token number">40</span><span class="token punctuation">,</span> bottom<span class="token punctuation">:</span> <span class="token number">20</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
            child<span class="token punctuation">:</span> <span class="token function">Row</span><span class="token punctuation">(</span>
              children<span class="token punctuation">:</span> <span class="token operator">&lt;</span>Widget<span class="token operator">&gt;</span><span class="token punctuation">[</span>
                <span class="token function">Padding</span><span class="token punctuation">(</span>
                  padding<span class="token punctuation">:</span> <span class="token keyword">const</span> EdgeInsets<span class="token punctuation">.</span><span class="token function">symmetric</span><span class="token punctuation">(</span>horizontal<span class="token punctuation">:</span> <span class="token number">16.0</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
                  child<span class="token punctuation">:</span> <span class="token function">ClipOval</span><span class="token punctuation">(</span>
                    <span class="token comment">// &#x5982;&#x679C;&#x5DF2;&#x767B;&#x5F55;&#xFF0C;&#x5219;&#x663E;&#x793A;&#x7528;&#x6237;&#x5934;&#x50CF;&#xFF1B;&#x82E5;&#x672A;&#x767B;&#x5F55;&#xFF0C;&#x5219;&#x663E;&#x793A;&#x9ED8;&#x8BA4;&#x5934;&#x50CF;</span>
                    child<span class="token punctuation">:</span> value<span class="token punctuation">.</span>isLogin
                        <span class="token operator">?</span> <span class="token function">gmAvatar</span><span class="token punctuation">(</span>value<span class="token punctuation">.</span>user<span class="token punctuation">.</span>avatar_url<span class="token punctuation">,</span> width<span class="token punctuation">:</span> <span class="token number">80</span><span class="token punctuation">)</span>
                        <span class="token punctuation">:</span> Image<span class="token punctuation">.</span><span class="token function">asset</span><span class="token punctuation">(</span>
                            <span class="token string">&quot;imgs/avatar-default.png&quot;</span><span class="token punctuation">,</span>
                            width<span class="token punctuation">:</span> <span class="token number">80</span><span class="token punctuation">,</span>
                          <span class="token punctuation">)</span><span class="token punctuation">,</span>
                  <span class="token punctuation">)</span><span class="token punctuation">,</span>
                <span class="token punctuation">)</span><span class="token punctuation">,</span>
                <span class="token function">Text</span><span class="token punctuation">(</span>
                  value<span class="token punctuation">.</span>isLogin
                      <span class="token operator">?</span> value<span class="token punctuation">.</span>user<span class="token punctuation">.</span>login
                      <span class="token punctuation">:</span> GmLocalizations<span class="token punctuation">.</span><span class="token function">of</span><span class="token punctuation">(</span>context<span class="token punctuation">)</span><span class="token punctuation">.</span>login<span class="token punctuation">,</span>
                  style<span class="token punctuation">:</span> <span class="token function">TextStyle</span><span class="token punctuation">(</span>
                    fontWeight<span class="token punctuation">:</span> FontWeight<span class="token punctuation">.</span>bold<span class="token punctuation">,</span>
                    color<span class="token punctuation">:</span> Colors<span class="token punctuation">.</span>white<span class="token punctuation">,</span>
                  <span class="token punctuation">)</span><span class="token punctuation">,</span>
                <span class="token punctuation">)</span>
              <span class="token punctuation">]</span><span class="token punctuation">,</span>
            <span class="token punctuation">)</span><span class="token punctuation">,</span>
          <span class="token punctuation">)</span><span class="token punctuation">,</span>
          onTap<span class="token punctuation">:</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
            <span class="token keyword">if</span> <span class="token punctuation">(</span><span class="token operator">!</span>value<span class="token punctuation">.</span>isLogin<span class="token punctuation">)</span> Navigator<span class="token punctuation">.</span><span class="token function">of</span><span class="token punctuation">(</span>context<span class="token punctuation">)</span><span class="token punctuation">.</span><span class="token function">pushNamed</span><span class="token punctuation">(</span><span class="token string">&quot;login&quot;</span><span class="token punctuation">)</span><span class="token punctuation">;</span>
          <span class="token punctuation">}</span><span class="token punctuation">,</span>
        <span class="token punctuation">)</span><span class="token punctuation">;</span>
      <span class="token punctuation">}</span><span class="token punctuation">,</span>
    <span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>

  <span class="token comment">// &#x6784;&#x5EFA;&#x83DC;&#x5355;&#x9879;</span>
  Widget <span class="token function">_buildMenus</span><span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
    <span class="token keyword">return</span> Consumer<span class="token operator">&lt;</span>UserModel<span class="token operator">&gt;</span><span class="token punctuation">(</span>
      builder<span class="token punctuation">:</span> <span class="token punctuation">(</span>BuildContext context<span class="token punctuation">,</span> UserModel userModel<span class="token punctuation">,</span> Widget child<span class="token punctuation">)</span> <span class="token punctuation">{</span>
        <span class="token keyword">var</span> gm <span class="token operator">=</span> GmLocalizations<span class="token punctuation">.</span><span class="token function">of</span><span class="token punctuation">(</span>context<span class="token punctuation">)</span><span class="token punctuation">;</span>
        <span class="token keyword">return</span> <span class="token function">ListView</span><span class="token punctuation">(</span>
          children<span class="token punctuation">:</span> <span class="token operator">&lt;</span>Widget<span class="token operator">&gt;</span><span class="token punctuation">[</span>
            <span class="token function">ListTile</span><span class="token punctuation">(</span>
              leading<span class="token punctuation">:</span> <span class="token keyword">const</span> <span class="token function">Icon</span><span class="token punctuation">(</span>Icons<span class="token punctuation">.</span>color_lens<span class="token punctuation">)</span><span class="token punctuation">,</span>
              title<span class="token punctuation">:</span> <span class="token function">Text</span><span class="token punctuation">(</span>gm<span class="token punctuation">.</span>theme<span class="token punctuation">)</span><span class="token punctuation">,</span>
              onTap<span class="token punctuation">:</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=</span><span class="token operator">&gt;</span> Navigator<span class="token punctuation">.</span><span class="token function">pushNamed</span><span class="token punctuation">(</span>context<span class="token punctuation">,</span> <span class="token string">&quot;themes&quot;</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
            <span class="token punctuation">)</span><span class="token punctuation">,</span>
            <span class="token function">ListTile</span><span class="token punctuation">(</span>
              leading<span class="token punctuation">:</span> <span class="token keyword">const</span> <span class="token function">Icon</span><span class="token punctuation">(</span>Icons<span class="token punctuation">.</span>language<span class="token punctuation">)</span><span class="token punctuation">,</span>
              title<span class="token punctuation">:</span> <span class="token function">Text</span><span class="token punctuation">(</span>gm<span class="token punctuation">.</span>language<span class="token punctuation">)</span><span class="token punctuation">,</span>
              onTap<span class="token punctuation">:</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=</span><span class="token operator">&gt;</span> Navigator<span class="token punctuation">.</span><span class="token function">pushNamed</span><span class="token punctuation">(</span>context<span class="token punctuation">,</span> <span class="token string">&quot;language&quot;</span><span class="token punctuation">)</span><span class="token punctuation">,</span>
            <span class="token punctuation">)</span><span class="token punctuation">,</span>
            <span class="token keyword">if</span><span class="token punctuation">(</span>userModel<span class="token punctuation">.</span>isLogin<span class="token punctuation">)</span> <span class="token function">ListTile</span><span class="token punctuation">(</span>
              leading<span class="token punctuation">:</span> <span class="token keyword">const</span> <span class="token function">Icon</span><span class="token punctuation">(</span>Icons<span class="token punctuation">.</span>power_settings_new<span class="token punctuation">)</span><span class="token punctuation">,</span>
              title<span class="token punctuation">:</span> <span class="token function">Text</span><span class="token punctuation">(</span>gm<span class="token punctuation">.</span>logout<span class="token punctuation">)</span><span class="token punctuation">,</span>
              onTap<span class="token punctuation">:</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                <span class="token function">showDialog</span><span class="token punctuation">(</span>
                  context<span class="token punctuation">:</span> context<span class="token punctuation">,</span>
                  builder<span class="token punctuation">:</span> <span class="token punctuation">(</span>ctx<span class="token punctuation">)</span> <span class="token punctuation">{</span>
                    <span class="token comment">//&#x9000;&#x51FA;&#x8D26;&#x53F7;&#x524D;&#x5148;&#x5F39;&#x4E8C;&#x6B21;&#x786E;&#x8BA4;&#x7A97;</span>
                    <span class="token keyword">return</span> <span class="token function">AlertDialog</span><span class="token punctuation">(</span>
                      content<span class="token punctuation">:</span> <span class="token function">Text</span><span class="token punctuation">(</span>gm<span class="token punctuation">.</span>logoutTip<span class="token punctuation">)</span><span class="token punctuation">,</span>
                      actions<span class="token punctuation">:</span> <span class="token operator">&lt;</span>Widget<span class="token operator">&gt;</span><span class="token punctuation">[</span>
                        <span class="token function">FlatButton</span><span class="token punctuation">(</span>
                          child<span class="token punctuation">:</span> <span class="token function">Text</span><span class="token punctuation">(</span>gm<span class="token punctuation">.</span>cancel<span class="token punctuation">)</span><span class="token punctuation">,</span>
                          onPressed<span class="token punctuation">:</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token operator">=</span><span class="token operator">&gt;</span> Navigator<span class="token punctuation">.</span><span class="token function">pop</span><span class="token punctuation">(</span>context<span class="token punctuation">)</span><span class="token punctuation">,</span>
                        <span class="token punctuation">)</span><span class="token punctuation">,</span>
                        <span class="token function">FlatButton</span><span class="token punctuation">(</span>
                          child<span class="token punctuation">:</span> <span class="token function">Text</span><span class="token punctuation">(</span>gm<span class="token punctuation">.</span>yes<span class="token punctuation">)</span><span class="token punctuation">,</span>
                          onPressed<span class="token punctuation">:</span> <span class="token punctuation">(</span><span class="token punctuation">)</span> <span class="token punctuation">{</span>
                            <span class="token comment">//&#x8BE5;&#x8D4B;&#x503C;&#x8BED;&#x53E5;&#x4F1A;&#x89E6;&#x53D1;MaterialApp rebuild</span>
                            userModel<span class="token punctuation">.</span>user <span class="token operator">=</span> <span class="token keyword">null</span><span class="token punctuation">;</span>
                            Navigator<span class="token punctuation">.</span><span class="token function">pop</span><span class="token punctuation">(</span>context<span class="token punctuation">)</span><span class="token punctuation">;</span>
                          <span class="token punctuation">}</span><span class="token punctuation">,</span>
                        <span class="token punctuation">)</span><span class="token punctuation">,</span>
                      <span class="token punctuation">]</span><span class="token punctuation">,</span>
                    <span class="token punctuation">)</span><span class="token punctuation">;</span>
                  <span class="token punctuation">}</span><span class="token punctuation">,</span>
                <span class="token punctuation">)</span><span class="token punctuation">;</span>
              <span class="token punctuation">}</span><span class="token punctuation">,</span>
            <span class="token punctuation">)</span><span class="token punctuation">,</span>
          <span class="token punctuation">]</span><span class="token punctuation">,</span>
        <span class="token punctuation">)</span><span class="token punctuation">;</span>
      <span class="token punctuation">}</span><span class="token punctuation">,</span>
    <span class="token punctuation">)</span><span class="token punctuation">;</span>
  <span class="token punctuation">}</span>
<span class="token punctuation">}</span>
</code></pre>
<p>&#x7528;&#x6237;&#x70B9;&#x51FB;&#x201C;&#x6CE8;&#x9500;&#x201D;&#xFF0C;<code>userModel.user</code> &#x4F1A;&#x88AB;&#x7F6E;&#x7A7A;&#xFF0C;&#x6B64;&#x65F6;&#x6240;&#x6709;&#x4F9D;&#x8D56;<code>userModel</code>&#x7684;&#x7EC4;&#x4EF6;&#x90FD;&#x4F1A;&#x88AB;<code>rebuild</code>&#xFF0C;&#x5982;&#x4E3B;&#x9875;&#x4F1A;&#x6062;&#x590D;&#x6210;&#x672A;&#x767B;&#x5F55;&#x7684;&#x72B6;&#x6001;&#x3002;</p>
<p>&#x672C;&#x5C0F;&#x8282;&#x6211;&#x4EEC;&#x4ECB;&#x7ECD;&#x4E86;APP&#x5165;&#x53E3;<code>MaterialApp</code>&#x7684;&#x4E00;&#x4E9B;&#x914D;&#x7F6E;&#xFF0C;&#x7136;&#x540E;&#x5B9E;&#x73B0;&#x4E86;APP&#x7684;&#x9996;&#x9875;&#x3002;&#x540E;&#x9762;&#x6211;&#x4EEC;&#x5C06;&#x5C55;&#x793A;&#x767B;&#x5F55;&#x9875;&#x3001;&#x6362;&#x80A4;&#x9875;&#x3001;&#x8BED;&#x8A00;&#x5207;&#x6362;&#x9875;&#x3002;</p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="network.html" class="navigation navigation-prev " aria-label="Previous page: 15.5：网络请求封装">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="login_page.html" class="navigation navigation-next " aria-label="Next page: 15.7：登录页">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"15.6：App入口及首页","level":"4.1.6","depth":2,"next":{"title":"15.7：登录页","level":"4.1.7","depth":2,"path":"chapter15/login_page.md","ref":"chapter15/login_page.md","articles":[]},"previous":{"title":"15.5：网络请求封装","level":"4.1.5","depth":2,"path":"chapter15/network.md","ref":"chapter15/network.md","articles":[]},"dir":"ltr"},"config":{"plugins":["-search","search-pro","ace","splitter","prism","donate","-highlight"],"root":"docs","styles":{"website":"styles/website.css","ebook":"styles/ebook.css","pdf":"styles/pdf.css","mobi":"styles/mobi.css","epub":"styles/epub.css"},"pluginsConfig":{"prism":{"lang":{"shell":"bash"}},"ace":{},"splitter":{},"search-pro":{"cutWordLib":"nodejieba","defineWord":["Gitbook Use"]},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"donate":{"alipay":"","alipayText":"支付宝打赏","button":"赏","title":"","wechat":"https://cdn.jsdelivr.net/gh/flutterchina/flutter-in-action@1.0.3/docs/imgs/pay.jpeg","wechatText":"微信打赏"},"fontsettings":{"theme":"white","family":"sans","size":2},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","author":"wendux 824783146@qq.com","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"《Flutter实战》","language":"zh-hans","links":{"sharing":{"all":null,"facebook":null,"google":null,"twitter":null,"weibo":null},"sidebar":{"<div><img height=20 style='position:relative; top:5px; padding-right:5px ' src='https://cdn.jsdelivr.net/gh/flutterchina/website@1.0/images/favicon.png'/> Flutter中文网</div>":"https://flutterchina.club"}},"gitbook":"*","description":"记录Gitbook的配置和一些插件的使用"},"file":{"path":"chapter15/entry.md","mtime":"2019-08-22T07:10:57.366Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2019-08-22T09:03:18.661Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>



    <script src="https://cdn.jsdelivr.net/gh/flutterchina/flutter-in-action/_book/gitbook/gitbook.js"></script>
    <script src="https://cdn.jsdelivr.net/gh/flutterchina/flutter-in-action/_book/gitbook/theme.js"></script>
    
        
        <script src="https://cdn.jsdelivr.net/gh/flutterchina/flutter-in-action/_book/gitbook/gitbook-plugin-search-pro/jquery.mark.min.js"></script>
        
    
        
        <script src="https://cdn.jsdelivr.net/gh/flutterchina/flutter-in-action/_book/gitbook/gitbook-plugin-search-pro/search.js"></script>
        
    
        
        <script src="https://cdn.jsdelivr.net/gh/flutterchina/flutter-in-action/_book/gitbook/gitbook-plugin-ace/ace/ace.js"></script>
        
    
        
        <script src="https://cdn.jsdelivr.net/gh/flutterchina/flutter-in-action/_book/gitbook/gitbook-plugin-ace/ace.js"></script>
        
    
        
        <script src="https://cdn.jsdelivr.net/gh/flutterchina/flutter-in-action/_book/gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="https://cdn.jsdelivr.net/gh/flutterchina/flutter-in-action/_book/gitbook/gitbook-plugin-donate/plugin.js"></script>
        
    
        
        <script src="https://cdn.jsdelivr.net/gh/flutterchina/flutter-in-action/_book/gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="https://cdn.jsdelivr.net/gh/flutterchina/flutter-in-action/_book/gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="https://cdn.jsdelivr.net/gh/flutterchina/flutter-in-action/_book/gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="https://cdn.jsdelivr.net/gh/flutterchina/flutter-in-action/_book/gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    


<script>
    var _hmt = _hmt || [];
    $("#bd").remove();
    (function () {
        var hm = document.createElement("script");
        hm.src = "https://hm.baidu.com/hm.js?170231fea4f81697eb046edc1a91fe5b";
        var s = document.getElementsByTagName("script")[0];
        hm.id = "bd"
        s.parentNode.insertBefore(hm, s);
    })();

    function init() {
        var p = location.pathname;
        _hmt.push(['_trackPageview', p]);
        if (p[p.length - 1] === '/') {
            p += "index.md"
        } else {
            p = p.split(".")[0] + ".md";
        }
        p = "https://github.com/flutterchina/flutter-in-action/blob/master/docs" + p;
        $(".pull-right .fa-edit").parent("a").attr("href", p);
        $("table").wrap("<div style='overflow: auto'></div>");
        //百度统计
        var e = /([http|https]:\/\/[a-zA-Z0-9\_\.]+\.baidu\.com)/gi, r = window.location.href,
            t = document.referrer;
        if (!e.test(r)) {
            var o = "https://sp0.baidu.com/9_Q4simg2RQJ8t7jm9iCKT-xh_/s.gif";
            t ? (o += "?r=" + encodeURIComponent(document.referrer), r && (o += "&l=" + r)) : r && (o += "?l=" + r);
            var i = new Image;
            i.src = o
        }
        $(".copyright").remove();
        $("<div class='copyright'> 本书仍在勘误阶段，请勿以任何形式私自传播，作者保留对本书的版权。</div>").appendTo(".page-inner");
    }

    function hookAPI(api, ob, fn) {
        return function () {
            var result = api.apply(ob, [].slice.call(arguments));
            setTimeout(fn, 1000);
            return result;
        }
    }

    function addAD() {
        if (location.href !== 'https://book.flutterchina.club/' && $("#book-search-results .ad").length == 0) {
            var id=Math.ceil(Math.random()*10)%2;
            $(".ad"+id).clone().hide().fadeIn().prependTo("#book-search-results")
            setTimeout(function () {
                $(".body-inner").animate({scrollTop: 0}, 200)
            }, 800);
        }
    }

    function _track(p,url) {
        _hmt.push(['_trackEvent', 'ad', 'click', p]);
        setTimeout(function () {
            location.href = url
        }, 100);
    }

    // setInterval(addAD, 300);

    init();

    if (history.pushState) {
        history.pushState = hookAPI(history.pushState, history, init);
    }

</script>
</body>

</html>

